package day240306.e3;

//可变参数，相当于数组
//variable-length argument

public class VarargTest {
    public static int add(int... a) {
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(add(1));
        System.out.println(add(1, 2));
        System.out.println(add(1, 2, 3));
        System.out.println(add(1, 2, 3, 4));
    }
}
